package org.chengn.level_middle.context82;

import org.chengn.definition.ListNode;

/**
 * @Title: Context82
 * @Author ChengN
 * @Package org.chengn.level_middle.context82
 * @Date 2024/1/15 0:09
 * @description: 删除排序链表中的重复元素Ⅱ
 */
public class Context82 {
    public ListNode deleteDuplicates(ListNode head) {
        if (head == null) return head;
        int val = head.val;
        int ans = 0;
        ListNode temp = head;
        while (temp != null && temp.val == val) {
            ans++;
            temp = temp.next;
        }

        if (ans > 1) return deleteDuplicates(temp);
        head.next = deleteDuplicates(temp);
        return head;
    }
}
